<?php

class frontendConfiguration extends sfApplicationConfiguration
{

    public function configure()
    {
        $this->dispatcher->connect('activity.log', array($this, 'listenToLogActivityEvent'));
    }

    /**
     * Logs every user activity
     * 
     * @param   sfEvent $event
     */
    public function listenToLogActivityEvent(sfEvent $event)
    {
        $parameters = $event->getParameters();
        $user = $parameters['user'];
        $points = isset($parameters['points']) ? $parameters['points'] : 0;
        
        $activityLog = new ActivityLog();
        $activityLog->setPoints($points);
        $activityLog->setDescription(trim($parameters['description']));
        $activityLog->setUser($user);
        $activityLog->save();

        if ($user->getType() == 'Doctor')
        {    
            // set doctor's level points
            $doctorLevel = $user->getDoctor()->getLevel();            
            $doctorLevel->setPoints(is_null($doctorLevel->getPoints()) ? $points : $doctorLevel->getPoints() + $points);
            $doctorLevel->save();
        }
    }
}

    